// 统一配置导出模块

const env = process.env.NODE_ENV || 'development';
const envConfig = require(`./env/${env}`);

const base = {
  db: require('./base/db'),
  redis: require('./base/redis'),
  cache: require('./base/cache'),
  captcha: require('./base/captcha'),
  logger: require('./base/logger'),
  code: require('./base/code'),
  schedules: require('./base/schedules'),
  upload: require('./base/upload')
};

const merge = (a, b) => ({ ...a, ...(b || {}) });

module.exports = {
  env,
  baseurl:envConfig.baseUrl,
  jwtConfig:envConfig.jwt,
  db: merge(base.db, envConfig.db),
  redis: merge(base.redis, envConfig.redis),
  cache: merge(base.cache, envConfig.cache),
  captcha: merge(base.captcha, envConfig.captcha),
  logger: merge(base.logger, envConfig.logger || envConfig.logging),
  code: merge(base.code, envConfig.code),
  schedules: merge(base.schedules, envConfig.schedules),
  upload: merge(base.upload, envConfig.upload)
};